﻿
@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}

@section header{
    <script type="text/javascript">
        function SaveBeforeCallBack() {
            if ($("#_ContName").val() == '') {
                layer.msg('温馨提示：必须填写套餐名称~！~'); return true;
            }
            if ($("#_StuNumber").val() == '') {
                layer.msg('温馨提示：必须填写学员人数~！~'); return true;
            }

            if ($('#leixing1').is(':checked')) {

                if ($("#_ClassHourNumber").val() == '') {

                    layer.msg('温馨提示：必须填写课时数~！~'); return true;
                }
                if ($("#_Price1").val() == '') {

                    layer.msg('温馨提示：必须填写价格~！~'); return true;
                }
                else {
                    $("#_Price").val($("#_Price1").val());
                }
            }
            if ($('#leixing0').is(':checked')) {

                if ($("#_HourNumber").val() == '') {

                    layer.msg('温馨提示：必须填写套餐时长~！~'); return true;
                }

                if ($("#_HourFrequency").val() == '') {

                    layer.msg('温馨提示：必须填写上课频次~！~'); return true;
                }
                if ($("#_Price2").val() == '') {

                    layer.msg('温馨提示：必须填写价格~！~'); return true;
                }
                else {
                    $("#_Price").val($("#_Price2").val());
                }
            }

            if ($("#_MaxLeave").val() == '') {
                layer.msg('温馨提示：必须填写最大请假次数~！~'); return true;
            }
            if ($("#_MaxMakeUP").val() == '') {

                layer.msg('温馨提示：必须填写最大补课数量~！~'); return true;
            }
            var number = '';
            $('input:checkbox[name=kc]:checked').each(function (k) {
                if (k == 0) {
                    number = $(this).val();
                } else {
                    number += ',' + $(this).val();
                }
            })

            if ($('#kecheng1').is(':checked') && number != '') {
                $("#_Courses").val(number);
            }
        }
    </script>
}

<input type="hidden" name="_Createdate" id="_Createdate" value="@ViewBag.data["Createdate"]" />
<input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
<input type="hidden" id="_IsClassHour" name="_IsClassHour" value="@ViewBag.data["IsClassHour"]">
<input type="hidden" id="_IsAll" name="_IsAll" value="@ViewBag.data["IsAll"]">
<input type="hidden" id="_Courses" name="_Courses" value="@ViewBag.data["Courses"]">
<input type="hidden" id="_Price" name="_Price" value="@ViewBag.data["Price"]">
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-form-item" style="margin-top:10px;">
            <label class="layui-form-label">套餐名称</label>
            <div class="layui-input-inline">
                <input type="text" id="_ContName" name="_ContName" required lay-verify="required" placeholder="请输入套餐名称" autocomplete="off" class="layui-input" value="@ViewBag.data["ContName"]">
            </div>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" id="_Remark" name="_Remark" required lay-verify="required" placeholder="请输入备注" autocomplete="off" class="layui-input" value="@ViewBag.data["Remark"]">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">套餐类型</label>
            <div class="layui-input-inline">
                <input type="radio" id="leixing1" name="leixing" value="1" title="课时" lay-skin="switch" lay-filter="IsClassHour1" @(ViewBag.data["IsClassHour"] == 1 ? "checked='checked'" : "")>
                <input type="radio" id="leixing0" name="leixing" value="0" title="时长" lay-skin="switch" lay-filter="IsClassHour0" @(ViewBag.data["IsClassHour"] == 0 ? "checked='checked'" : "")>
            </div>
        </div>
        <div id="shichang" style="display:block">
            <div class="layui-form-item">
                <label class="layui-form-label" id="ContType">套餐时长</label>
                <div class="layui-input-inline">
                    <input type="text" id="_HourNumber" name="_HourNumber" required lay-verify="required" placeholder="请输入套餐时长" autocomplete="off" class="layui-input" value="@ViewBag.data["HourNumber"]">
                </div>
                <div class="layui-form-mid layui-word-aux">/月</div>
                <label class="layui-form-label">价格</label>
                <div class="layui-input-inline">
                    <input type="number" id="_Price2" name="" required lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item" id="ContType1">
                <label class="layui-form-label">上课频次</label>
                <div class="layui-input-inline">
                    <input type="text" id="_HourFrequency" name="_HourFrequency" required lay-verify="required" placeholder="请输入上课频次" autocomplete="off" class="layui-input" value="@ViewBag.data["HourFrequency"]">
                </div>
                <div class="layui-form-mid layui-word-aux">/月</div>
            </div>
        </div>
        <div id="keshi" style="display:none">
            <div class="layui-form-item">
                <label class="layui-form-label" id="ContType">课时数</label>
                <div class="layui-input-inline">
                    <input type="text" id="_ClassHourNumber" name="_ClassHourNumber" required lay-verify="required" placeholder="请输入课时数" autocomplete="off" class="layui-input" value="@ViewBag.data["ClassHourNumber"]">
                </div>
                <label class="layui-form-label">价格</label>
                <div class="layui-input-inline">
                    <input type="text" id="_Price1" name="" required lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input" value="">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">最大请假</label>
            <div class="layui-input-inline">
                <input type="text" id="_MaxLeave" name="_MaxLeave" required lay-verify="required" placeholder="请输入最大请假次数" autocomplete="off" class="layui-input" value="@ViewBag.data["MaxLeave"]">
            </div>
            <label class="layui-form-label">最大补课</label>
            <div class="layui-input-inline">
                <input type="text" id="_MaxMakeUP" name="_MaxMakeUP" required lay-verify="required" placeholder="请输入最大补课次数" autocomplete="off" class="layui-input" value="@ViewBag.data["MaxMakeUP"]">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程</label>
            <div class="layui-input-inline">
                <input type="radio" id="kecheng0" name="kecheng" value="0" title="全部" lay-skin="switch" lay-filter="_IsAll0" @(ViewBag.data["IsAll"] == 0 ? "checked='checked'" : "")>
                <input type="radio" id="kecheng1" name="kecheng" value="1" title="部分" lay-skin="switch" lay-filter="_IsAll1" @(ViewBag.data["IsAll"] == 1 ? "checked='checked'" : "")>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" id="CousrseList">

            </div>
        </div>
    </div>
</div>



<script>

    layui.use(['form', 'laydate'], function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#BirdDate' //指定元素
            , value: new Date()
        });


    });
</script>
<script>
    $(function () {
            if (@ViewBag.data["IsClassHour"]==1) {
                $("#shichang").hide();
                $("#keshi").show();
            }
        $.ajax({
            url: "../MealCourses/MealCourse/CourseData?id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
            dataType: "json",
            data: '',
            success: function (data) {
                if (data.code = "0000") {
                    if (data.data) {
                        var str = "";
                        var obj = data.data;
                        var bfdata = "@ViewBag.data["Courses"]";
                        var list = bfdata.split(',');
                        for (var i = 0; i < obj.length; i++) {
                            var is_true = false;
                            for (var j = 0; j < list.length; j++) {
                                if (parseInt(list[j]) == obj[i].id) {
                                    is_true = true;
                                    break;
                                }
                            }
                            if (is_true) {//查找单选框里的这门课程是否被选择，选择就勾上
                                str += '\t<input type=\"checkbox\" name=\"kc\" title=\"' + obj[i].Name + '\" value=\"' + obj[i].id + '\"  id=\"' + obj[i].id + '\"  checked>\n';
                            }
                            else {
                                str += '\t<input type=\"checkbox\" name=\"kc\" title=\"' + obj[i].Name + '\" value=\"' + obj[i].id + '\"  id=\"' + obj[i].id + '\"  >\n';
                            }

                        }
                        //console.log(str)
                        layui.form.render();
                        $("#CousrseList").append(str);
                        if (@ViewBag.data["IsAll"]==1) {
                            layui.form.render();
                        }
                    }
                }
                else if (data.code == "0001") {
                    layer.msg("您没有权限！");
                }
            }
        });
    });

    layui.use('form', function () {
        var form = layui.form;
        //各种基于事件的操作，下面会有进一步介绍
        //监听指定开关
        form.on('radio(_IsAll1)', function (data) {
            if (this.checked) {
                //$(":checkbox").prop("checked", false);
                $("#CousrseList").show();
                form.render();
                $("#_IsAll").val("1");
            }
            else {
            }
        });
        //监听指定开关
        form.on('radio(_IsAll0)', function (data) {
            if (this.checked) {
                $("#CousrseList").hide();
                form.render();
                $("#_IsAll").val("0");
            }
            else {
            }
        });

        //监听指定开关
        form.on('radio(IsClassHour1)', function (data) {
            if (this.checked) {
                $("#shichang").hide();
                $("#keshi").show();
                $("#_IsClassHour").val("1");
            }
            else {
                $("#keshi").hide();
                $("#shichang").show();
            }
        });
        //监听指定开关
        form.on('radio(IsClassHour0)', function (data) {
            if (this.checked) {
                $("#keshi").hide();
                $("#shichang").show();
                $("#_IsClassHour").val("0");
            }
            else {
                $("#shichang").hide();
                $("#keshi").show();
            }
        });
        //监听指定开关
        form.on('switch(IsTentative)', function (data) {
            if (this.checked) {
                $("#_IsTentative").val("0");
            }
            else {
                $("#_IsTentative").val("1");
            }
        });

        //监听指定开关
        form.on('switch(State)', function (data) {
            if (this.checked) {
                $("#_State").val("0");
            }
            else {
                $("#_State").val("1");
            }
        });
    })
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

@section fooler{
    <script>
    if (@ViewBag.Lx== 1)//编辑状态赋值数据。岁月数据，字段名一致就可以自动赋值。不一致要自己转换，.Lx==1表示编辑状态
    {
        var Price =@ViewBag.data["Price"];
        if ($('#leixing0').is(':checked')) {
            $("#_Price2").val(Price);
        }
        if ($('#leixing1').is(':checked')) {
            $("#_Price1").val(Price);
        }
    }
    </script>
}

